//
//  ZFDownloadedCell.m
//
// Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "ZFDownloadedCell.h"
#import "Masonry.h"

@interface ZFDownloadedCell ()

@property(nonatomic, strong)UIImageView *playView;

@end

@implementation ZFDownloadedCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubview];
        
    }
    
    return self;
    
}

- (void)createSubview {
    
    self.playView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.playView];
    self.playView.image = [UIImage imageNamed:@"video_list"];
    
    self.fileNameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.fileNameLabel];
    
    self.sizeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.sizeLabel];
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [self.playView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(self.contentView.mas_height).multipliedBy(1. / 3.);
        make.width.mas_equalTo(self.playView.mas_height).multipliedBy(1. / 1.);
        make.left.mas_equalTo(self.contentView).equalTo(@20);
        
    }];
    
    
    [self.fileNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(1. / 1.8);
        make.left.mas_equalTo(self.playView.mas_right).equalTo(@10);
        make.height.mas_equalTo(self.fileNameLabel.mas_width).multipliedBy(1. / 7.);
        
    }];
    
    [self.sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.contentView).equalTo(@-10);
        make.right.mas_equalTo(self.contentView).equalTo(@-10);
        make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(1. / 7);
        make.height.mas_equalTo(self.fileNameLabel.mas_width).multipliedBy(1. / 7.);
    
    }];
    
    
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

-(void)setDownloadObject:(ZFDownloadObject *)downloadObject
{
    _downloadObject = downloadObject;
    self.fileNameLabel.text = downloadObject.fileName;
    self.sizeLabel.text = downloadObject.totalLenghtToString;
}

@end
